package org.yaac.client.conf;

import javax.inject.Singleton;

import org.yaac.client.YaacShell;
import org.yaac.client.activity.BlobActivity;
import org.yaac.client.activity.BrowserActivity;
import org.yaac.client.activity.EGQLActivity;
import org.yaac.client.activity.EditorActivity;
import org.yaac.client.activity.MenuActivity;
import org.yaac.client.activity.OverviewActivity;
import org.yaac.client.activity.StatisticsActivity;
import org.yaac.client.channel.ChannelClientManager;
import org.yaac.client.ui.BlobView;
import org.yaac.client.ui.BlobViewImpl;
import org.yaac.client.ui.BrowserView;
import org.yaac.client.ui.BrowserViewImpl;
import org.yaac.client.ui.EGQLView;
import org.yaac.client.ui.EGQLViewImpl;
import org.yaac.client.ui.EditorPropertyPanel;
import org.yaac.client.ui.EditorView;
import org.yaac.client.ui.EditorViewImpl;
import org.yaac.client.ui.MenuTreeViewModel;
import org.yaac.client.ui.MenuView;
import org.yaac.client.ui.MenuViewImpl;
import org.yaac.client.ui.Overview;
import org.yaac.client.ui.OverviewImpl;
import org.yaac.client.ui.StatisticsView;
import org.yaac.client.ui.StatisticsViewImpl;
import org.yaac.client.util.ExceptionManager;

import com.google.gwt.activity.shared.ActivityManager;
import com.google.gwt.activity.shared.ActivityMapper;
import com.google.gwt.inject.client.AbstractGinModule;
import com.google.gwt.place.shared.PlaceController;
import com.google.gwt.place.shared.PlaceHistoryHandler;
import com.google.gwt.place.shared.PlaceHistoryMapper;
import com.google.inject.name.Names;
import com.google.web.bindery.event.shared.EventBus;
import com.google.web.bindery.event.shared.SimpleEventBus;

/**
 * @author Max Zhu (thebbsky@gmail.com)
 * 
 */
public class YaacGinModule extends AbstractGinModule {

	@Override
	protected void configure() {
		// MVP related
		bind(EventBus.class).to(SimpleEventBus.class).in(Singleton.class);
		bind(PlaceHistoryMapper.class).to(YaacPlaceHistoryMapper.class).in(Singleton.class);
		bind(PlaceController.class).toProvider(YaacPlaceControllerProvider.class).in(Singleton.class);
		bind(PlaceHistoryHandler.class).toProvider(YaacPlaceHistoryHandlerProvider.class).in(Singleton.class);
		
		// MVP related : main activity
		bind(ActivityMapper.class).annotatedWith(Names.named(BindingConstants.MAIN_ACTIVITY_MAPPER)).to(
				MainActivityMapper.class).in(Singleton.class);
		bind(ActivityManager.class).annotatedWith(Names.named(BindingConstants.MAIN_ACTIVITY_MANAGER)).toProvider(
				MainActivityManagerProvider.class).in(Singleton.class);

		// MVP related : menu activity
		bind(ActivityMapper.class).annotatedWith(Names.named(BindingConstants.MENU_ACTIVITY_MAPPER)).to(
				MenuActivityMapper.class).in(Singleton.class);
		bind(ActivityManager.class).annotatedWith(Names.named(BindingConstants.MENU_ACTIVITY_MANAGER)).toProvider(
				MenuActivityManagerProvider.class).in(Singleton.class);
		
		// main shell
		bind(YaacShell.class).in(Singleton.class);
		// main menu
		bind(MenuTreeViewModel.class).in(Singleton.class);
		
		// exception manager
		bind(ExceptionManager.class).in(Singleton.class);
		
		// channel manager
		bind(ChannelClientManager.class).in(Singleton.class);
		
		// views
		bind(Overview.class).to(OverviewImpl.class).in(Singleton.class);
		bind(MenuView.class).to(MenuViewImpl.class).in(Singleton.class);
		bind(StatisticsView.class).to(StatisticsViewImpl.class).in(Singleton.class);
		bind(BrowserView.class).to(BrowserViewImpl.class).in(Singleton.class);
		bind(EditorView.class).to(EditorViewImpl.class).in(Singleton.class);
		bind(EditorPropertyPanel.class).in(Singleton.class);
		bind(EGQLView.class).to(EGQLViewImpl.class).in(Singleton.class);
		bind(BlobView.class).to(BlobViewImpl.class).in(Singleton.class);
		
		// activities
		// places will be created inside activities
		bind(MenuActivity.class).in(Singleton.class);
		bind(OverviewActivity.class); 
		bind(StatisticsActivity.class);
		bind(BrowserActivity.class);
		bind(EditorActivity.class);
		bind(EGQLActivity.class);
		bind(BlobActivity.class);
	}
}
